<?php
/**
 * @package  nuo
 * @author   Nam Nguyen <nam.ngvan@gmail.com>
 * @version  1.0
 * @since    Apr 17, 2013
 */
class Nuo_Session
{

	/**
	 * @static
	 * @access  private
	 * @var     Nuo_Session_Abstract
	 */
	static private $_handler = NULL;

	/**
	 * Initialize Session
	 * @link nuo/init
	 * @static
	 * @access   public
	 * @return   void
	 */
	static public function init()
	{
		if (self::$_handler)
		{
			return;
		}

		if (!defined('NUO_SESSION') or NUO_SESSION)
		{
			$config = Nuo::readConfigFile('session');
			$class = 'Nuo_Session_' . ucfirst($config['adapter']);
			$handler = new $class($config['options']);
		}
		else
		{
			$handler = new Session_Null;
		}

		@session_set_save_handler(array(
			$handler,
			'open'
		), array(
			$handler,
			'close'
		), array(
			$handler,
			'read'
		), array(
			$handler,
			'write'
		), array(
			$handler,
			'destroy'
		), array(
			$handler,
			'gc'
		));

		if (!defined('NUO_SESSION') or NUO_SESSION)
		{
			session_start();
		}

		self::$_handler = $handler;
	}

}
